import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import { Row, Col, Card, Form, Input, Button, DatePicker, Tag } from 'antd';
import TableList from '@/components/TableList';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from '../../search.less';

const { RangePicker } = DatePicker;
const FormItem = Form.Item;
@Form.create()
/* eslint react/no-multi-comp:0 */
@connect(({ draw, loading }) => ({
  draw,
  loading: loading.models.draw,
}))
class DrawTable extends PureComponent {
  state = {
    selectedRows: [],
    formValues: {},
  };

  columns = [
    {
      title: '数据库名',
      dataIndex: 'dbName',
      key: 'dbName',
    },    
    {
      title: '表名',
      dataIndex: 'tableName',
      key: 'tableName',
    },

    {
      title: '列名',
      dataIndex: 'colsName',
      key: 'colsName',      
    }, 
    {
      title: '路径',
      dataIndex: 'url',
      key: 'url',
    }, 

  ];

  componentDidMount() {
    this.pageList();
  }
  // 分页查询列表
  pageList(formValues = {}, pageSize = 10, pageNum = 0) {
    const { dispatch } = this.props;
    const values = {
      pageSize: pageSize,
      pageNum: pageNum,
      taskName: formValues.taskName,      
    };
    dispatch({
      type: 'draw/queryTableList2',
      payload: values,
    });
  }

  handleStandardTableChange(pagination) {
    const { formValues } = this.state;
    // 分页请求
    this.pageList(formValues, pagination.pageSize, pagination.current - 1);
  }

  render() {
    const {
      draw: { data2 },
      loading,
    } = this.props;
    const { selectedRows } = this.state;
    return (    
        <Fragment>
           <TableList
              selectedRows={selectedRows}
              loading={loading}
              data={data2}
              columns={this.columns}             
              size="middle"
              hideRowSelection
              rowKey="id"
              pagination={false}
              onChange={this.handleStandardTableChange.bind(this)}
            />
        </Fragment>
    );
  }
}

export default DrawTable;
